home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
FromTheMag
/
JW FLV MEDIA PLAYER 4.2
/
mediaplayer.exe
/
player.swf
/
scripts
/
com
/
jeroenwijering
/
parsers
/
SMILParser.as
< prev
next >
Wrap
Text File
|
2008-11-04
|
4KB
|
136 lines
package com.jeroenwijering.parsers
{
import com.jeroenwijering.utils.Strings;
public class SMILParser extends ObjectParser
{
public function SMILParser()
{
super();
}
public static function parseAttributes(param1:Object, param2:Object) : Object
{
var _loc3_:Number = NaN;
var _loc4_:String = null;
_loc3_ = 0;
while(_loc3_ < param1.attributes().length())
{
_loc4_ = param1.attributes()[_loc3_].name().toString();
switch(_loc4_)
{
case "begin":
param2["start"] = Strings.seconds(param1.@begin);
break;
case "src":
param2["file"] = param1.@src.toString();
break;
case "dur":
param2["duration"] = Strings.seconds(param1.@dur);
break;
case "alt":
param2["description"] = param1.@alt.toString();
break;
default:
param2[_loc4_] = param1.attributes()[_loc3_].toString();
break;
}
_loc3_++;
}
return param2;
}
public static function parse(param1:XML) : Array
{
var _loc2_:Array = null;
var _loc3_:Object = null;
var _loc4_:XML = null;
var _loc5_:XML = null;
_loc2_ = new Array();
_loc3_ = new Object();
if((_loc4_ = param1.children()[1].children()[0]).localName().toLowerCase() == "seq")
{
for each(_loc5_ in _loc4_.children())
{
_loc3_ = SMILParser.parseSeq(_loc5_);
if(_loc3_["type"] != undefined)
{
_loc2_.push(_loc3_);
}
_loc3_ = {};
}
}
else
{
_loc2_.push(SMILParser.parsePar(_loc4_));
}
return _loc2_;
}
public static function parseSeq(param1:Object) : Object
{
var _loc2_:Object = null;
_loc2_ = new Object();
switch(param1.localName().toLowerCase())
{
case "par":
_loc2_ = SMILParser.parsePar(param1);
break;
case "img":
case "video":
case "audio":
_loc2_ = SMILParser.parseAttributes(param1,_loc2_);
}
return ObjectParser.complete(_loc2_);
}
public static function parsePar(param1:Object) : Object
{
var _loc2_:Object = null;
var _loc3_:XML = null;
_loc2_ = new Object();
for each(_loc3_ in param1.children())
{
switch(_loc3_.localName())
{
case "anchor":
_loc2_["link"] = _loc3_.@href.toString();
break;
case "textstream":
_loc2_["captions"] = _loc3_.@src.toString();
break;
case "img":
case "video":
case "audio":
_loc2_[_loc3_.localName()] = _loc3_.@src.toString();
_loc2_ = SMILParser.parseAttributes(_loc3_,_loc2_);
break;
}
}
if(_loc2_["video"])
{
_loc2_["file"] = _loc2_["video"];
delete _loc2_["video"];
}
else if(_loc2_["audio"])
{
_loc2_["file"] = _loc2_["audio"];
delete _loc2_["audio"];
}
else if(_loc2_["img"])
{
_loc2_["file"] = _loc2_["img"];
delete _loc2_["audio"];
}
if(_loc2_["img"])
{
_loc2_["image"] = _loc2_["img"];
delete _loc2_["img"];
}
return _loc2_;
}
}
}